package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Auther: Sun
 * @Date: 2025/9/25 - 09 - 25 - 14:30
 * @Description: com.itheima.aop
 */
@Component
//@Aspect
@Slf4j
public class MyAspect1 {
    @Pointcut("execution(* com.itheima.service.impl.*.*(..))")
    private void pt(){

    }
    //前置通知在目标方法运行前运行
    @Before("pt()")
    public void before(){
        log.info("before...");
    }
    @Around(" pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around before...");
        Object result = joinPoint.proceed();
        log.info("around after...");
        return result;
    }
    //后置通知在目标方法运行后运行,无论是否出现异常都会运行
    @After("pt()")
    public void after(){
        log.info("after...");
    }
    //返回后通知，如果出现异常不会运行
    @AfterReturning("pt()")
    public void afterReturning(){
        log.info("afterReturning...");
    }
    //异常通知，如果出现异常会运行
    @AfterThrowing("pt()")
    public void afterThrowing(){
        log.info("afterThrowing...");
    }

}
